/**
 * 2017年12月19日
 */
package exp.paper.core;

import java.util.ArrayList;
import java.util.List;

import exp.algorithm.sic.InstanceFeatureVectors;
import exp.algorithm.sic.ScalePeak;
import exp.algorithm.sic.TimeSeries;

/**
 * @author Alex
 *
 */
public class LightPyramid {
	public static int octaveNum = 4;
    public ArrayList<LightOctaveSpace> octaves; // 该塔中一共有几个8度空间
    int    scaleSpaceLevels         = 3;    
    float octaveSigma              = 1.6f;   // 用于处理每个8度空间图像的模糊因子
    int    minimumRequiredPixelsize = 32;    // 高斯金字塔中缩小时最小的尺寸
    PointFinder pf = new PointFinder();
    public LightPyramid() {
    	
	}
    public int buildOctaves(TimeSeries ts){
    	return buildOctaves(ts, 1.0f, scaleSpaceLevels, octaveSigma, minimumRequiredPixelsize);
    }
    
    public void output(){
    	for(LightOctaveSpace los:octaves){
    		System.out.println(los.toString());
    	}
    }
    
    private int buildOctaves(TimeSeries source, float scale, int levelsPerOctave, float octaveSigm, int minSize) {
        this.octaves = new ArrayList<LightOctaveSpace>();
        LightOctaveSpace downSpace = null;
        TimeSeries prev = source;
        int k = octaveNum;
        while (prev != null && k>0/* && prev.width >= minSize && prev.height >= minSize*/) {
        	LightOctaveSpace osp = new LightOctaveSpace();
            osp.indexInPyramid = octaveNum-k;
            // Create both the gaussian filtered images and the DOG maps
            osp.makeGaussianImgs(prev, scale, levelsPerOctave, octaveSigm);
            osp.makeGaussianDiffImgs();
            octaves.add(osp);
            prev = osp.getLastGaussianImg().halved();
            if (downSpace != null) downSpace.up = osp;
            osp.down = downSpace;
            downSpace = osp;
            scale *= 2.0;
            k--;
        }
        return (octaves.size());
    }
    InstanceFeatureVectors getFeatureVecotrs(){
    	return null;
    }
    
    public void clear(){
    	for(LightOctaveSpace los:this.octaves){
    		los.clear();
    	}
    }
}
